#include "mypushbutton.h"
#include <QRect>

MyPushButton::MyPushButton(QWidget *parent)
    : QPushButton(parent)
{

}

void MyPushButton::enterEvent(QEvent *ev)
{

    QWidget* parent = this->parentWidget();
    if(parent)
    {
        int w = parent->geometry().width();
        int h = parent->geometry().height();
        int x = rand() % w;
        int y = rand() % h;
        //在父窗口中找到名为 "pushButton_2" 的按钮
        QPushButton* pushButton = parent->findChild<QPushButton*>("pushButton_2");
        if(pushButton)
        {
            QRect rect = pushButton->geometry();
            pushButton->setGeometry(x,y,rect.width(),rect.height());
        }
    }
}
